{% extends "base/base.html" %}
{% block body %} 
	<div class='blockContent'>
		<div class='toolDiv'>
			<label>名称</label>
			<input class='condField' key='name'></input>
			<button class='query' callFunc='click:queryModule'>查询</button>
			<button class='add' callFunc='click:addModule'>添加</button>
		</div>
		<div class='tableDiv' id='formTable'>
				<div id='tableHead'></div>
				<div id='tableBody'></div>
		</div>
	</div>
	
{% endblock %}

{% block script %}
	//表格配置 begin head配置  属性 bindFunc,name,css,sortKey,sortByDefault,headcss
    {% block handle %}
    	var handle={
    		name:'',
    		serv:''
    	};
    {% endblock%}
    {% block listhead %}
		var listHeadCfg={}
    	//模板
		var renderTemplate=$("<div class='table_template'>"+
								"<div class='tr'>"+
										"<div class='td' jtext='name'></div>"+
										"<div class='td' jtext='content'></div>"+
										"<div class='td' jtext='priority'></div>"+													
										"<div class='td' jtext='schedule'></div>"+
										"<div class='td' jtext='ctrl'></div>"+			
								"</div>"+
							"</div>");
    {% endblock %}
        
	var table=$("#formTable");	
	var body=table.children("#tableBody");
	body.listTable({
		head:table.children("#tableHead"),
		//头配置
		curCfg:listHeadCfg,
		//模板
		curTemp:renderTemplate
	});	
	{% block listfunc %}
		tableHandle.addFunc("ctrl",function(){
			return $("<button class='btn' callFunc='click:editTemplate'>编辑</button>"+
					"<button class='btn' callFunc='click:delTemplate'>删除</button>");
		},body);								
	{% endblock %}							
	yanhx.addCommon("load",function(){
		queryTemplate({page:1,pageSize:15});
        {% block load %}
        {% endblock %}
	});
	
	yanhx.addFunc("addModule",function(){
		top.yanhx.exec("tabHandle.openTabFromCurTab",{
			tabKey:'addHtml',
			tabName:'新建'+handle.name,
			tabSrc:'/do?action='+handle.serv+'.add',
			callback:'updateTable'
		});
	});
	
	yanhx.addFunc("updateTable",function(data){
	
		tableHandle.exec({
			table:body,
			func:'update',
			data:data
		});
	})
	
	yanhx.addFunc("editTemplate",function(){
		var data=tableHandle.exec({
			table:body,
			func:'getRowData',
			data:$src()
		});
		top.yanhx.exec("tabHandle.openTabFromCurTab",{
			tabKey:'editHtml'+data.id,
			tabName:'编辑'+handle.name,
			tabSrc:'/do?action='+handle.serv+'.gotoEdit&id='+data.id,
			callback:'updateTable'
		});
		
	});
	yanhx.addFunc("delTemplate",function(){
		var rowData=tableHandle.exec({
			table:body,
			func:'getRowData',
			data:$src()
		});
		yanhx.exec("myWin.confirm",{
			content:'确定删除 '+rowData.name+" 这条纪录?",
			y:function(){
				$.postJSON("/do?action="+handle.serv+".delRow",{id:rowData.id},function(data){
					yanhx.exec("myWin.alert",{
						content:data.message,
						func:function(){
							tableHandle.exec({
								table:body,
								func:'delRowData',
								data:rowData.id
							});
						}	
					});
					data=null;
				});
			}
		});
	});
	yanhx.addFunc("queryModule",function(){
		var cond=yanhx.exec("fillQryCond",{elem:this.parent().find(".condField")});
		cond.page=1;
		cond.pageSize=15;
		queryTemplate(cond);
	});
	function queryTemplate(cond){
		$.getJSON("/do?action="+handle.serv+".query",cond,function(data){
			table.children("#tableBody").listTable({
				clean:true,
				data:data.rows
			});
            table.page(data.total,cond,queryTemplate);        
		});
	}
    yanhx.addFunc("showDetail",function(){
    	var rowData=body.$tableRow();
        $.postJSON("/do?action="+handle.serv+".detail",{id:rowData.id},function(data){
       		yanhx.exec("myWin.open",{
           		elem:$(data.content).addClass("yanhx_detail"),
           		title:rowData.name,
           		model:true
            });
        });     
    });               
    {% block other %}
        //扩展选项
    {% endblock %}                
{% endblock %}
			